package psd.model.Prolog.Converters;

import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.ThisExpression;

import psd.model.IConverter;
import psd.model.Prolog.FactGenerationToolbox;
import psd.model.Prolog.PrologConverter;


public class PrologThisExpressionConverter extends PrologConverter
implements IConverter<ThisExpression>{

	public PrologThisExpressionConverter(FactGenerationToolbox toolbox) {
		super(toolbox);
	}

	@Override
	public boolean convert(ThisExpression node) {
		 String args[];
	        String type;
	        if(node.getQualifier() == null)
	        {
	            args = (new String[] {
	                "this", idResolver.getID(node.resolveTypeBinding())
	            });
	            type = "identT";
	            writeSourceLocationArgumentRaw(node, "identifier(this)", node.getStartPosition(), node.getLength());
	        } else
	        {
	            args = (new String[] {
	                "this", typeResolver.getTypeTerm((ITypeBinding)node.getQualifier().resolveBinding()), idResolver.getID(node.getQualifier().resolveTypeBinding())
	            });
	            type = "selectT";
	            writeSourceLocationArgumentIdentifier(node, node.getQualifier());
	        }
	        createBodyFact(node, type, args);
	        return true;
	}

}
